【发布时间】:2017-10-27 10:20:06
【问题描述】:
有人可以帮我从 python 中的多个网页中提取数据
我想将 460 页中的客户姓名、客户评论和时间提取到 CSV 文件中。 这里是 Url
【问题讨论】:
标签: python-3.x beautifulsoup scrapy web-crawler
有人可以帮我从 python 中的多个网页中提取数据
我想将 460 页中的客户姓名、客户评论和时间提取到 CSV 文件中。 这里是 Url
【问题讨论】:
标签: python-3.x beautifulsoup scrapy web-crawler
如果你要报废的站点总是相同的,你可以使用 Selenium,更简单快捷,但必须知道页面的 html 代码。当您必须废弃始终相同的页面时,这是一个更好的解决方案
例如:
from selenium import webdriver
path_to_chromedriver = "C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python36-32\\chromedriver.exe" # change path as needed
browser = webdriver.Chrome(executable_path = path_to_chromedriver)
url = "http://www.mouthshut.com/mobile-operators/Reliance-Jio-reviews-925812061"
browser.get(url)
res = browser.find_elements_by_css_selector('div.col-2.profile')
for item in res:
try:
user = item.find_element_by_tag_name("a")
print(user.get_attribute("href"))
except Exception as e:
print("ERROR", e)
你也可以使用 xpath 查看本站http://selenium-python.readthedocs.io/locating-elements.html
【讨论】: