0
点赞
收藏
分享

微信扫一扫

求大神解答:利用python爬取各县GDP结果为空,求大神看看我的代码问题在哪?

目标url=红黑人口库


代码

import requests

from lxml import etree

import time

if __name__ =='__main__':

   url = 'https://pagead2.googlesyndication.com/getconfig/sodar?sv=200&tid=gda&tv=r20221020&st=env'

     #'https://pagead2.googlesyndication.com/getconfig/sodar?sv=200&tid=gda&tv=r20221020&st=env'

   headers = {'User-Agent': 'User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;',

              'Referer': 'https://www.hongheiku.com/',


   }

   response = requests.get(url=url, headers=headers).text

   html = etree.HTML(response)

   divs = html.xpath('/html/body/section/div[1]/div/article/table/tr[@class="even"]')

   print(response)


   for div in divs:

       area=div.xpath('//a/center/text()')

       GDP=div.xpath('//td[3]/center/text()')

       year=div.xpath('//td[4]/center/text()')

       #title='saas'.join(div.xpath('./div/div[3]/a/text()'))

       #companyname=div.xpath('./div/a/div[2]/div[1]/div/text()')[0]

       print(GDP)


举报

相关推荐

0 条评论