在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/數(shù)據(jù)分析&挖掘  Python/ 請教一個爬蟲相關(guān)的問題

請教一個爬蟲相關(guān)的問題

藥監(jiān)局網(wǎng)站

http://app2.sfda.gov.cn/datas...

有需求需要從藥監(jiān)局網(wǎng)站抓取一點數(shù)據(jù),發(fā)現(xiàn)藥監(jiān)局網(wǎng)站反爬蟲無法破解(狀態(tài)碼返回 202,無法抓到正確的 html),想求教一下各位大佬有沒有解決辦法?

已經(jīng)嘗試過的方法:
1.requests + fake_useragent
2.PhantomJS + selenium
3.requests_html 的 render() (pyppeteer+Chromium)

回答
編輯回答
赱丅呿

python 3.5環(huán)境 把chromedriver的路徑改成自己的就可以運行了

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait

chrome_opt = webdriver.ChromeOptions()
prefs = {"profile.managed_default_content_settings.images":2}
chrome_opt.add_experimental_option("prefs", prefs)
browser = webdriver.Chrome(executable_path="E:\selenium\chromedriver.exe", chrome_options=chrome_opt)
browser.set_window_position(-10, 0)
pageNum = 1
countNum = 1
while True:

print("\n當(dāng)前頁數(shù):%d"%pageNum)
browser.get("http://app2.sfda.gov.cn/datasearchp/gzcxSearch.do?page=%d&searchcx=&optionType=V1&paramter0=null&paramter1=null&paramter2=null&formRender=cx"%pageNum)
browser.execute_script("var q=document.documentElement.scrollTop=270")
allProduct = WebDriverWait(browser, 10).until(lambda x: x.find_elements_by_xpath('/html/body/center/table[4]/tbody/tr[2]/td/center/table/tbody/tr[3]/td/table[1]/tbody/tr'))
for product in allProduct:
    if (product.get_attribute("name") != None):
        cpmc = WebDriverWait(product, 10).until(lambda x: x.find_element_by_xpath('./td[1]')).text
        gcyp = WebDriverWait(product, 10).until(lambda x: x.find_element_by_xpath('./td[2]/table/tbody/tr/td[2]/table/tbody/tr/td[2]/font')).text
        jkyp = WebDriverWait(product, 10).until(lambda x: x.find_element_by_xpath('./td[2]/table/tbody/tr/td[4]/table/tbody/tr/td[2]/font')).text
        ypgg = WebDriverWait(product, 10).until(lambda x: x.find_element_by_xpath('./td[2]/table/tbody/tr/td[6]/table/tbody/tr/td[2]/font')).text
        print("編號:%s, 產(chǎn)品名稱:%s, 國產(chǎn)藥品:%s, 進口藥品:%s, 藥品廣告:%s"%(countNum, cpmc, gcyp, jkyp, ypgg))
        countNum += 1
if (len(allProduct) != 30) : break
pageNum += 1
2017年10月31日 16:04
編輯回答
冷眸

用requests帶cookie去訪問是可以得到200的,看了一下cookie獲取過程比較復(fù)雜,簡單快速的直接用selenium就可以了,樓上代碼親測可行

2017年8月12日 09:01