【发布时间】:2016-03-01 20:09:18
【问题描述】:
我想从具有以下形式的 URL 的网站中提取一些信息: http://www.pedigreequery.com/american+pharoah 其中“american+pharoah”是许多马名之一的扩展名。 我有一个我要搜索的马名列表,我只需要弄清楚如何在“http://www.pedigreequery.com/”之后插入名称
这是我目前拥有的:
import csv
allhorses = csv.reader(open('HORSES.csv') )
rows=list(allhorses)
import requests
from bs4 import BeautifulSoup
for i in rows: # Number of pages plus one
url = "http://www.pedigreequery.com/".format(i)
r = requests.get(url)
soup = BeautifulSoup(r.content)
letters = soup.find_all("a", class_="horseName")
print(letters)
当我打印出网址时,它的末尾没有马的名字,只有引号中的网址。最后的信件/打印声明只是为了检查它是否真的进入了网站。 这就是我所看到的循环最后按数字更改的 URL 的方式——我还没有找到关于按字符更改的 URL 的建议。
谢谢!
【问题讨论】:
标签: python web-scraping beautifulsoup