我正在尝试从以下url中删除学校名称:https://www.niche.com/k12/search/best-public-high-schools/s/indiana/?page=1
我想刮10页,因此是for循环。我以前从未使用过beautifulsoup,文档也没有解决我的问题。最后,我想把学校的名字划掉,因为那是学校的名字所在地。下面是我的少量代码。任何帮助都会非常有用!谢谢
import bs4 as bs
import requests
numbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
names = []
for number in numbers:
resp = requests.get('https://www.niche.com/k12/search/best-public-high-schools/s/indiana/?page='+number)
soup = bs.BeautifulSoup(resp.text, "lxml")
school_names = soup.find('div', {'class':'"search-results"'})
for school_name in school_names:
school = school_name.find('h2')
if school:
print (school.text)
你试图抓取的网页有验证码,这使得收集数据变得困难。请查看此链接:
https://sqa.stackexchange.com/questions/17022/how-to-fill-captcha-using-test-automation
通过传递头试试这个。使用https://curl.trillworks.com/作为助手,我可以得到:
这给了我200分,而不是403分。当然,上面的头是冗长的(我从我的浏览器中复制了这个),您可能可以使用试用和错误来查看实际需要哪些头(我猜这只是少数),以保证
200 OK
相关问题 更多 >
编程相关推荐