鱼C论坛

 找回密码
 立即注册
查看: 1679|回复: 3

[已解决]爬虫问题

[复制链接]
发表于 2021-9-14 16:24:21 | 显示全部楼层 |阅读模式
20鱼币
https://www.ncbi.nlm.nih.gov/biosample/SAMEA1030995
  1.             oresp=requests.get(url="https://www.ncbi.nlm.nih.gov/biosample/SAMEA1030995",headers=headers)
  2.             print(oresp.text)
  3.             html1=etree.HTML(oresp.content)
  4.             htmldata1=html1.xpath('//div[@id="maincontent"]/div/div[5]/div/div[1]/dl[3]/dd/table/tbody/tr[2]/td/text()')
复制代码


为什么爬不出中间的'GP580'
最佳答案
2021-9-14 16:24:22
我尝试了etree,貌似读这个html会报错,用re取到了。

  1. import requests
  2. import re


  3. def main():
  4.     url = 'https://www.ncbi.nlm.nih.gov/biosample/SAMEA1030995'
  5.     headers = {'user-agent': 'firefox'}
  6.     r = requests.get(url, headers=headers)
  7.     result = re.findall(r'sample name</th><td>(.*?)</td>', r.text)
  8.     print(result)


  9. if __name__ == '__main__':
  10.     main()
复制代码

最佳答案

查看完整内容

我尝试了etree,貌似读这个html会报错,用re取到了。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-9-14 16:24:22 | 显示全部楼层    本楼为最佳答案   
我尝试了etree,貌似读这个html会报错,用re取到了。

  1. import requests
  2. import re


  3. def main():
  4.     url = 'https://www.ncbi.nlm.nih.gov/biosample/SAMEA1030995'
  5.     headers = {'user-agent': 'firefox'}
  6.     r = requests.get(url, headers=headers)
  7.     result = re.findall(r'sample name</th><td>(.*?)</td>', r.text)
  8.     print(result)


  9. if __name__ == '__main__':
  10.     main()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-9-14 17:25:57 | 显示全部楼层
自己顶一下 有没有帮帮我~
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-9-14 17:42:36 | 显示全部楼层
suchocolate 发表于 2021-9-14 16:24
我尝试了etree,貌似读这个html会报错,用re取到了。

其实我也用re解决了。。但还是想试试etree这种结构找到。。不过我没去试beautifulsoup。。应该可以
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-18 17:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表