我想通过 Python、selenium、firefox 获取 Airbnb 列表页面的 URL,但是,我的程序运行不佳。
我的错误代码如下;
Original exception was:
Traceback (most recent call last):
File "pages.py", line 19, in <module>
for links in driver.find_element_by_xpath('//div[contains(@id, "listing-")]//a[contains(@href, "rooms")]'):
TypeError: 'FirefoxWebElement' object is not iterable
Run Code Online (Sandbox Code Playgroud)
这是我的代码!
from selenium import webdriver
from selenium.webdriver import FirefoxOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
test_url = 'https://www.airbnb.jp/s/%E6%97%A5%E6%9C%AC%E6%B2%96%E7%B8%84%E7%9C%8C/homes?refinement_paths%5B%5D=%2Fhomes&query=%E6%97%A5%E6%9C%AC%E6%B2%96%E7%B8%84%E7%9C%8C&price_min=15000&allow_override%5B%5D=&checkin=2018-07-07&checkout=2018-07-08&place_id=ChIJ51ur7mJw9TQR79H9hnJhuzU&s_tag=z4scstF7'
opts = FirefoxOptions()
opts.add_argument("--headless")
driver = webdriver.Firefox(firefox_options=opts)
driver.get(test_url)
driver.implicitly_wait(30)
for links in driver.find_element_by_xpath('//div[contains(@id, "listing-")]//a[contains(@href, "rooms")]'):
listing_url = …Run Code Online (Sandbox Code Playgroud) 我试图从亚马逊抓取产品信息,但遇到了问题。当蜘蛛到达页面末尾时它会停止,我想为我的程序添加一种方法来一般搜索页面的下 3 页。我正在尝试编辑 start_urls,但我无法从函数解析内部执行此操作。此外,这没什么大不了的,但程序出于某种原因两次请求相同的信息。提前致谢。
import scrapy
from scrapy import Spider
from scrapy import Request
class ProductSpider(scrapy.Spider):
product = input("What product are you looking for? Keywords help for specific products: ")
name = "Product_spider"
allowed_domains=['www.amazon.ca']
start_urls = ['https://www.amazon.ca/s/ref=nb_sb_noss_2?url=search-alias%3Daps&field-keywords='+product]
#so that websites will not block access to the spider
download_delay = 30
def parse(self, response):
temp_url_list = []
for i in range(3,6):
next_url = response.xpath('//*[@id="pagn"]/span['+str(i)+']/a/@href').extract()
next_url_final = response.urljoin(str(next_url[0]))
start_urls.append(str(next_url_final))
# xpath is similar to an address that is used to find certain …Run Code Online (Sandbox Code Playgroud) 我是网络抓取的新手,我想获取此网页的数据:http : //www.neotroptree.info/data/countrysearch
在此链接中,我们看到四个字段(国家、域、州和站点)。
我有一个包含站点名称的数据框,我使用以下代码对其进行了抓取:
ipak <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}
ipak(c("rgdal", "tidyverse"))
#> Loading required package: rgdal
#> Loading required package: sp
#> rgdal: version: 1.3-4, (SVN revision 766)
#> Geospatial Data Abstraction Library extensions to R successfully loaded
#> Loaded GDAL runtime: GDAL 2.2.2, released 2017/09/15
#> Path to GDAL shared files: /usr/share/gdal/2.2
#> GDAL binary built with GEOS: TRUE
#> Loaded …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Puppeteer 登录 Instagram,但不知何故我无法做到。
你能帮助我吗?
这是我正在使用的链接:
https://www.instagram.com/accounts/login/
我尝试了不同的东西。我试过的最后一个代码是这样的:
const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://www.instagram.com/accounts/login/');
await page.evaluate();
await afterJS.type('#f29d14ae75303cc', 'username');
await afterJS.type('#f13459e80cdd114', 'password');
await page.pdf({path: 'page.pdf', format: 'A4'});
await browser.close();
})();
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我正在使用网站抓取 npm 来抓取网站, https://github.com/website-scraper/node-website-scraper
我已经从保存在assests文件夹中的网站获取了图像。现在我需要在这个脚本需要创建的新动态 html 中显示图像并显示这些图像。我看到了这篇文章:用 JavaScript 创建 HTML 文件, 但它似乎没有帮助。
如何仅使用 JavaScript 创建 HTML?创建一个真正的 html 文件并将其保存在本地。还是我应该使用 Nodejs?将图像传递到服务器端并将图像附加到 hbs?其他选择?
在我的日常任务中,我目前必须搜索大量产品并收集有关这些产品的信息。所以我的想法是在 google 上搜索产品,并通过从产品标题部分提取数据来从第一个搜索结果中获取信息,并且几乎对许多产品进行循环。
到目前为止,这是我的代码:
Sub SkuAutomation()
Dim ie As Object
'Navigates to google
Set ie = CreateObject("InternetExplorer.application")
ie.Visible = True
ie.Navigate "https://google.co.uk/search?q=" & Worksheets("sheet1").Cell(9, 4).Value & " " & Worksheets("sheet1").Cells(9, 2)
'Waits for page to load before next action
Do While ie.ReadyState <> READYSTATE_COMPLETE
Loop
End Sub
Run Code Online (Sandbox Code Playgroud)
我只想添加一段代码,要么点击谷歌返回的第一个链接,要么为我返回链接。我的想法是从该页面的产品标题部分抓取数据!不过还是非常早期的阶段。
我只是一个初学者,所以任何类型的帮助都将不胜感激!提前谢谢了。
我正在尝试使用请求和 BeautifulSoup 来抓取网站。当我运行代码来获取网页的标签时,soup 对象是空白的。我把请求对象打印出来看看请求是否成功,没有。打印结果显示响应 447。我无法找到 447 作为 HTTP 状态代码的含义。有谁知道我如何成功连接和抓取网站?
代码:
r = requests.get('https://foobar)
soup = BeautifulSoup(r.text, 'html.parser')
print(soup.get_text())
Output:
''
Run Code Online (Sandbox Code Playgroud)
当我打印请求对象时:
print(r)
Output:
<Response [447]>
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的问题。我正在尝试从linkedIn 页面的html 中获取工作描述,但是我没有获取页面的html,而是得到了几行看起来像javascript 代码的行。我对此很陌生,因此将不胜感激任何帮助!谢谢
这是我的代码:
import requests
url = "https://www.linkedin.com/jobs/view/inside-sales-manager-at-stericycle-1089095836/"
page_html = requests.get(url).text
print(page_html)
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我没有得到我期望包含工作描述的 html...我只是得到了几行 javascript 代码。
我正在尝试向 scrapy.FormRequest 对象提供表单数据。formdata 是以下结构的字典:
{
"param1": [
{
"paramA": "valueA",
"paramB": "valueB"
}
]
}
Run Code Online (Sandbox Code Playgroud)
通过相当于以下代码,在scrapy shell中运行:
from scrapy import FormRequest
url = 'www.example.com'
method_post = 'POST'
formdata = <the above dict>
fr = FormRequest(url=url, method=method_post, formdata=formdata)
fetch(fr)
Run Code Online (Sandbox Code Playgroud)
作为回应,我收到以下错误:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/chhk/.local/share/virtualenvs/project/lib/python3.6/site-packages/scrapy/http/request/form.py", line 31, in __init__
querystr = _urlencode(items, self.encoding)
File "/Users/chhk/.local/share/virtualenvs/project/lib/python3.6/site-packages/scrapy/http/request/form.py", line 66, in _urlencode
for k, vs in seq
File "/Users/chhk/.local/share/virtualenvs/project/lib/python3.6/site-packages/scrapy/http/request/form.py", line 67, in <listcomp>
for v in …Run Code Online (Sandbox Code Playgroud) 我试图从这个网站上抓取之前的收盘价和开盘价。这是一张图像,作为要抓取的信息所在位置的参考。
看起来特定表是带有 的div标签的子表class="col-lg-13",但 bs4 只是None在所有尝试找到它时返回。
我尝试了以下方法:
from bs4 import BeautifulSoup
import requests
link = "https://bseindia.com/stock-share-price/bharat-gears-ltd/bharatgear/505688/"
resp = requests.get(link).content
soup = BeautifulSoup(resp, "lxml")
box = soup.find('div', class_="col-lg-13")
table = box.find('table')
print(table)
>>> None
Run Code Online (Sandbox Code Playgroud)
我也试过:
container = soup.find('div', attr={'ng-init': "fnStockTrading()"})
tables = container.find_all('table')
print(tables)
>>> []
Run Code Online (Sandbox Code Playgroud) web-scraping ×10
python ×4
python-3.x ×3
javascript ×2
node.js ×2
scrapy ×2
automation ×1
excel ×1
form-data ×1
html ×1
http ×1
puppeteer ×1
r ×1
request ×1
rvest ×1
scrapy-shell ×1
selenium ×1
vba ×1
web ×1
xpath ×1