是否可以使用just get方法实现无限量的读取废料。例如
http://www.justdial.com/Ahmedabad/Bearing-Dealers/ct-302676
当我们向下滚动时,为每个页面提供以下链接
^{pr2}$到目前为止,我的代码看起来像:
import requests
def readJustDial(c):
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'none',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive'}
for i in range(1,10):
url = 'http://www.justdial.com/functions/ajxsearch.php?national_search=0&act=pagination&city='+str(c)+'&search=Bearing+Dealers&where=&catid=302676&psearch=&prid=&page='+str(i)+'&SID=&mntypgrp=0&toknbkt=&bookDate=&jdsrc='
page = requests.get(url,hdr)
def main(): #this is main function of this program
allCities=["Ahmedabad","Hyderabad","Bangalore","Kolkata","Chennai","Mumbai","Delhi-NCR","Pune"]
for city in allCities:
readJustDial(city)
#print(city)
if __name__ == "__main__":
main()
也请建议我可以对我的现有代码进行任何更改。我只是在学习python,所以任何建议都是好的。在
尝试模仿正常工作的浏览器xhr请求附带的标题。您可以使用浏览器的开发工具(我使用chrome的)查看这些标题。 当我查看请求时,我看到它是用以下标题发送的:
尝试用这些头发送一个请求,除了cookies(通常它们只是临时工作)。在
如果那也不管用,你就需要饼干了。您可以使用浏览器(例如使用selenium),也可以对网页或Cookie进行反向工程,并尝试编写一个获取工作cookie的方法。在
相关问题 更多 >
编程相关推荐