0
getメソッドを使用して無限の読み取りスクラップを実現することは可能ですか?例えば、 requests.getメソッドpythonを使用した無限スクロール
http://www.justdial.com/Ahmedabad/Bearing-Dealers/ct-302676
たちはスクロールダウン各ページの次のリンクを与える
http://www.justdial.com/functions/ajxsearch.php?national_search=0&act=pagination&city=Ahmedabad&search=Bearing+Dealers&where=&catid=302676&psearch=&prid=&page=2&SID=&mntypgrp=0&toknbkt=&bookDate=&jdsrc=
http://www.justdial.com/functions/ajxsearch.php?national_search=0&act=pagination&city=Ahmedabad&search=Bearing+Dealers&where=&catid=302676&psearch=&prid=&page=3&SID=&mntypgrp=0&toknbkt=&bookDate=&jdsrc=
は、これまでの私のコードは次のようになります。すべての変更を提案してくださいまた、
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を学んでいるので、どんな提案も良いでしょう。
私にはうまく見えます。あなたのコードはあなたのニーズをどのように満たしていませんか? – Ouroborus
@Ouroborusaccessが拒否されました...もしあなたがそのページ(2ページ目または3ページ目)を開こうとすると、ブラウザで実際に開くことはできません。空リストを表示します。 –
リファラーとクッキーが必要です。 – Ouroborus