如何用Python抓取动态网页 [我想做什么]
在下面的网页上搜索二手车数据。如何用Python抓取动态网页 [我想做什么],python,html,web-scraping,beautifulsoup,scrape,Python,Html,Web Scraping,Beautifulsoup,Scrape,在下面的网页上搜索二手车数据。 [问题] 刮去整页。在上面的url中,仅显示前30项。我在下面写的代码可以把它们删掉。其他页面的链接显示为1 2 3。。。但是链接地址似乎是用Javascript编写的。我在谷歌上搜索有用的信息,但没有找到 from bs4 import BeautifulSoup import urllib.request html = urllib.request.urlopen("http://www.goo-net.com/php/search/summary.php
[问题] 刮去整页。在上面的url中,仅显示前30项。我在下面写的代码可以把它们删掉。其他页面的链接显示为1 2 3。。。但是链接地址似乎是用Javascript编写的。我在谷歌上搜索有用的信息,但没有找到
from bs4 import BeautifulSoup
import urllib.request
html = urllib.request.urlopen("http://www.goo-net.com/php/search/summary.php?price_range=&pref_c=08,09,10,11,12,13,14&easysearch_flg=1")
soup = BeautifulSoup(html, "lxml")
total_cars = soup.find(class_="change change_01").find('em').string
tmp = soup.find(class_="change change_01").find_all('span')
car_start, car_end = tmp[0].string, tmp[1].string
# get urls to car detail pages
car_urls = []
heading_inners = soup.find_all(class_="heading_inner")
for heading_inner in heading_inners:
href = heading_inner.find('h4').find('a').get('href')
car_urls.append('http://www.goo-net.com' + href)
for url in car_urls:
html = urllib.request.urlopen(url)
soup = BeautifulSoup(html, "lxml")
#title
print(soup.find(class_='hdBlockTop').find('p', class_='tit').string)
#price of car itself
print(soup.find(class_='price1').string)
#price of car including tax
print(soup.find(class_='price2').string)
tds = soup.find(class_='subData').find_all('td')
# year
print(tds[0].string)
# distance
print(tds[1].string)
# displacement
print(tds[2].string)
# inspection
print(tds[3].string)
[我想知道的]
如何刮整页。我更喜欢使用BeautifulSoup4(Python)。但如果这不是合适的工具,请给我看其他的
[我的环境]
- Windows 8.1
- Python 3.5
- PyDev(Eclipse)
- 美丽之路4
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://example.com')
element = driver.find_element_by_class_name("yourClassName") #or find by text or etc
element.click()
谢谢你的回答。这是我第一次了解DOM,我可以让它做“选择这个元素”和“单击那个元素”之类的事情?现在我正在阅读splinter网站。@Dixham,请随意点击任何接近答案的答案旁边的勾号。在StackOverflow上接受答案的经过验证的历史将鼓励更多的人回答您随后的问题。嗨。。你认为你能帮我吗