我正在尝试从 vivino.com 抓取 Wine 数据并使用 selenium 使其自动化并抓取尽可能多的数据。我的代码如下所示:
import time
from selenium import webdriver
browser = webdriver.Chrome('C:\Program Files (x86)\chromedriver.exe')
browser.get('https://www.vivino.com/explore?e=eJwFwbEOQDAUBdC_uaNoMN7NZhQLEXmqmiZaUk3x987xkVXRwLtAVcLLy7qE_tiN0Bz6FhcV7M4s0ZkkB86VUZIL9l4kmyjW4ORmbo0nTTPVDxlkGvg%3D&cart_item_source=nav-explore') # Vivino Website with 5 wines for now (simple example). Plan to scrape around 10,000 wines
lenOfPage = browser.execute_script("window.scrollTo(0, document.body.scrollHeight);var lenOfPage=document.body.scrollHeight;return lenOfPage;")
match=False
while(match==False):
lastCount = lenOfPage
time.sleep(7)
lenOfPage = browser.execute_script("window.scrollTo(0, document.body.scrollHeight);var lenOfPage=document.body.scrollHeight;return lenOfPage;")
if lastCount==lenOfPage:
match=True
Run Code Online (Sandbox Code Playgroud)
这将打开一个包含 5 种葡萄酒的网站并向下滚动。现在我想一一点击葡萄酒的超链接以获取有关其价格、酿酒葡萄种类等的信息。因此,基本上我的脚本将尝试向下滚动以允许在页面上显示尽可能多的葡萄酒,然后单击第一个超链接,获取附加信息并返回。然后,该过程将重复。我不认为这是一个有效的策略,但这就是我目前想到的。
我的问题是 vivino 网站中的超链接。href 链接附近没有文本,它允许我使用find_element_by_link_text函数:
<a class="anchor__anchor--2QZvA" href="/weingut-r-a-pfaffl-austrian-cherry-zweigelt/w/1261542?year=2018&price_id=23409078&cart_item_source=direct-explore" target="_blank">
Run Code Online (Sandbox Code Playgroud)
您能否建议如何单击超链接后没有文本的带有硒的葡萄酒?我在网络搜索期间没有找到正确的答案。提前致谢
我制作了一个在我的计算机上运行良好的 node.js 网络抓取代码,但是,当我部署到运行 Debian 的 Google Cloud VM 实例时,它会返回特定网站的超时错误。我已经为 puppeteer 尝试了许多不同的设置,但似乎都不起作用。我相信当我从谷歌云服务器运行时,我试图抓取的网站会阻止我的代码,但当我从我的计算机运行时不会。抓取部分在我的电脑上运行良好。Puppeteer 找到 HTML 标签并检索信息。
const puppeteer = require('puppeteer');
const GoogleSpreadsheet = require('google-spreadsheet');
const { promisify } = require('util');
const credentials = require('./credentials.json');
async function main(){
const scrapCopasa = await scrapCopasaFunction();
console.log('Done!')
}
async function scrapCopasaFunction() {
const browser = await puppeteer.launch({
args: ['--no-sandbox'],
});
const page = await browser.newPage();
//await page.setDefaultNavigationTimeout(0);
//await page.setViewport({width: 1366, height: 768});
await page.setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36');
await page.goto('http://www.copasa.com.br/wps/portal/internet/abastecimento-de-agua/nivel-dos-reservatorios');
//await …Run Code Online (Sandbox Code Playgroud) javascript node.js web-scraping google-cloud-platform puppeteer
我正在尝试使用 urllib 包从网页下载 csv 文件。要从该站点下载 csv 文件,必须发送带有适当参数的 post 请求。
当我尝试使用请求模块时,我可以完美地下载文件。但是,当我尝试使用 urllib 包做同样的事情时,我也得到了一个 csv 文件,但这次文件只包含标题。尸体不见了。
以下是从该站点手动下载该文件的方法:
Site address: https://www.nyiso.com/custom-reports?report=dam_lbmp_zonal
Zones: CAPITL, CENTRL
Version: Latest
Format: CSV
Hit `Generate Report` button
Run Code Online (Sandbox Code Playgroud)
以下脚本仅下载 csv 文件中的标题:
import csv
import urllib.request
import urllib.parse
link = "http://dss.nyiso.com/dss_oasis/PublicReports"
params = {
'reportKey': 'DAM_LBMP_ZONE',
'startDate': '04/17/2021',
'endDate': '04/17/2021',
'version': 'L',
'dataFormat': 'CSV',
'filter': ['CAPITL','CENTRL'],
}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36'
}
data = urllib.parse.urlencode(params).encode()
req = urllib.request.Request(link, data=data, headers=headers) …Run Code Online (Sandbox Code Playgroud) 好的,我有这个代码:
public static string ScreenScrape(string url)
{
System.Net.WebRequest request = System.Net.WebRequest.Create(url);
// set properties of the request
using (System.Net.WebResponse response = request.GetResponse())
{
using (System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream()))
{
return reader.ReadToEnd();
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想过滤文本以获得div class ="comment"除了使用正则表达式之外还有其他选项吗?或者这是唯一的方法?
谢谢
我有这样的文件用Python解析(从报废):
some HTML and JS here...
SomeValue =
{
'calendar': [
{ 's0Date': new Date(2010, 9, 12),
'values': [
{ 's1Date': new Date(2010, 9, 17), 'price': 9900 },
{ 's1Date': new Date(2010, 9, 18), 'price': 9900 },
{ 's1Date': new Date(2010, 9, 19), 'price': 9900 },
{ 's1Date': new Date(2010, 9, 20), 'price': 9900 },
{ 's1Date': new Date(2010, 9, 21), 'price': 9900 },
{ 's1Date': new Date(2010, 9, 22), 'price': 9900 },
{ 's1Date': new Date(2010, 9, 23), 'price': …Run Code Online (Sandbox Code Playgroud) 我一直在努力编写过去几个小时的程序,我认为这是一个非常简单的任务:
我尝试过使用带有lxml的Xpath,但没有经验,每一个结构都带有一个空白数组.
报价的实际内容似乎包含在"sqq"类中.
如果我通过Firebug导航网站,单击DOM选项卡,它出现在textNode属性"wholeText"或"textContent"中 - 但我不知道如何以编程方式使用该知识.
有任何想法吗?
我有一个脚本适用于我想要抓取的99%的页面,但只有少数几个没有我想要的东西而且我的脚本错误了
undefined method `attribute' for nil:NilClass (NoMethodError)
Run Code Online (Sandbox Code Playgroud)
从摆弄和调试代码有点难看,但这就是我正在做的事情.错误在第三行,只是因为在错误情况下没有.entry-content img:
doc = Nokogiri::HTML(open(url))
image_link = doc.css(".entry-content img")
temp = image_link.attribute('src').to_s
Run Code Online (Sandbox Code Playgroud)
当Nokogiri返回的image_link不是nil时,如何检测到这一点并处理错误?
我已经看过一些网络广播,需要帮助才能做到这一点:我一直在使用lxml.html.雅虎最近改变了网络结构.
目标页面;
http://finance.yahoo.com/quote/IBM/options?date=1469750400&straddle=true
在使用检查器的Chrome中:我看到了数据
//*[@id="main-0-Quote-Proxy"]/section/section/div[2]/section/section/table
Run Code Online (Sandbox Code Playgroud)
那么一些代码
如何将这些数据输出到列表中.我想换成其他股票从"LLY"到"Msft"?
如何在日期之间切换....并获得所有月份.
我正在使用Windows的网站下载程序爬行维基百科,我正在查看此工具中的所有选项,以查找下载特定时期的维基百科页面的选项,例如从2005年开始直到现在.
有没有人知道在特定时间内抓取网站?
我正在尝试使用PHP来搜索Google搜索结果.
我尝试使用@file_get_contents(http://www.google.com/search?hl=en&q=test),但它不起作用.它仅适用于http://www.google.com.
我尝试使用curl代替.这是我的功能:
function my_fetch($url,$user_agent='Mozilla/4.0 (compatible; MSIE
5.01; Windows NT 5.0)') {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_REFERER, 'http://www.google.com/');
$result = curl_exec ($ch);
curl_close ($ch);
return $result; }
$googleContent = my_fetch("http://www.google.com/search?hl=en&q=test");
echo $googleContent;
Run Code Online (Sandbox Code Playgroud)
结果是
302 Moved
The document has moved here.
Run Code Online (Sandbox Code Playgroud)
点击此处链接:http://www.google.com/sorry/?continue = http://www.google.com/search%3Fhl%3Den%26q%3Dtest
有没有办法使用PHP抓取搜索结果而无需学习API?
web-scraping ×10
python ×5
lxml ×2
c# ×1
html-parsing ×1
javascript ×1
json ×1
node.js ×1
nokogiri ×1
php ×1
post ×1
puppeteer ×1
python-3.x ×1
ruby ×1
screen ×1
selenium ×1
urllib ×1
web-crawler ×1
yahoo ×1