我想从这个页面(和类似的页面)抓取数据:https : //cereals.ahdb.org.uk/market-data-centre/historical-data/feed-ingredients.aspx
此页面使用Power BI。不幸的是,找到一种抓取Power BI 的方法很困难,因为每个人都想抓取使用/进入 Power BI,而不是从中抓取。最接近的答案是这个问题。却又不相干。
首先,我使用了Apache tika,很快我意识到加载页面后正在加载表数据。我需要页面的渲染版本。
因此,我使用了Selenium。我想Select All在开始时(发送Ctrl+A组合键),但它不起作用。可能是受页面事件限制(我也尝试使用开发人员工具删除所有事件,但仍然Ctrl+A不起作用。
我还尝试阅读 HTML 内容,但 Power BIdiv使用position:absolute并区分div表中 a 的位置(行和列)将元素放在屏幕上是一项费力的活动。
由于 Power BI 使用 JSON,我尝试从那里读取数据。然而,它是如此复杂,我无法找到规则。它似乎将关键字放在某处并在表中使用它们的索引。
注意:我意识到所有数据都没有加载,甚至没有同时显示。甲div类scroll-bar-part-bar是负责作为滚动条,并移动该加载/节目的数据的其他部分。
我用来读取数据的代码如下。如前所述,生成数据的顺序与浏览器上呈现的顺序不同:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
options = webdriver.ChromeOptions()
options.binary_location = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
driver = webdriver.Chrome(options=options, …Run Code Online (Sandbox Code Playgroud) 我正在开发一个项目,我想在后台搜索一个网站的内容,并从该网站获取一些有限的内容.例如,在我的页面中,我有"userid"和"password"字段,通过使用那些我将访问我的邮件并抓取我的收件箱内容并将其显示在我的页面中.
我通过单独使用javascript完成了上述操作.但是,当我单击登录按钮时,我的页面的URL(http://localhost/web/Login.html)将更改为URL(http://mail.in.com/mails/inbox.php?nomail= ......)我被刮掉了.但我在不改变我的网址的情况下废弃了细节.
我想废弃一个包含地址,电子邮件等用户列表的网页.网页包含分页用户列表,即当我点击第2页链接时页面包含10个用户链接它将通过AJAX加载用户列表第2页并更新列表所以所有分页链接.
网站是在asp扩展.aspx页面开发的,因为我对asp.net一无所知以及asp如何管理分页和AJAX
我使用简单的html dom http://sourceforge.net/projects/simplehtmldom/来废弃包含
对于拥有用户的页面,<=10 我不必模拟AJAX请求,就像用户点击分页链接一样
但对于有分页从其他页面获取数据的页面,我正在模拟后AJAX请求
require 'simple_html_dom.php';
$html = file_get_html('www.example.com/user_list.aspx');
$viewstate = $html->find("#__VIEWSTATE");
$viewstate = $viewstate[0]->attr['value'];
$eventvalidation = $html->find("#__EVENTVALIDATION");
$eventvalidation = $eventvalidation[0]->attr['value'];
$number_of_pageinations = 3;
$pageNumberCodes = array(
'ctl00$cphMainContent$rdpMembers$ctl01$ctl01',
'ctl00$cphMainContent$rdpMembers$ctl01$ctl02',
'ctl00$cphMainContent$rdpMembers$ctl01$ctl03'
); // this code is added for each page in POST as __EVENTTARGET
for ($i = 0; $i < $number_of_pageinations; $i++) {
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_ENCODING => "", // handle …Run Code Online (Sandbox Code Playgroud) 我想在scrapy.Item中添加一个字段,这样它就是一个数组:
class MyItem(scrapy.Item):
field1 = scrapy.Field()
field2 = scrapy.Field()
field3_array = ???
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
有没有人有刮刮SEC 10-K和10-Q备案的经验?我试图从这些文件中删除每月实现的股票回购时遇到困难.具体而言,我想获得以下信息:1.期间; 2.购买的股份总数; 3.每股平均支付价格; 4.作为公开宣布的计划或计划的一部分购买的股份总数; 5.从2004年到2014年,每个月根据计划或计划购买的股票的最大数量(或近似美元价值).我总共有90,000多种表格需要解析,所以这样做是不可行的手动.
此信息通常在10-Ks的"第2部分项目5注册人普通股权市场,相关股东事项和发行人购买股权证券"和"第2部分第2项未注册的股权证券销售和所得款项用途"中报告.
以下是我需要解析的10-Q文件的一个示例:https: //www.sec.gov/Archives/edgar/data/12978/000104746909007169/a2193892z10-q.htm
如果公司没有股票回购,则季度报告中可能会缺少此表.
我试图用Python BeautifulSoup解析html文件,但结果并不令人满意,主要是因为这些文件不是以一致的格式编写的.
例如,我能想到解析这些表单的唯一方法是
from bs4 import BeautifulSoup
import requests
import unicodedata
import re
url='https://www.sec.gov/Archives/edgar/data/12978/000104746909007169/a2193892z10-q.htm'
def parse_html(url):
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html5lib')
tables = soup.find_all('table')
identifier = re.compile(r'Total.*Number.*of.*Shares.*\w*Purchased.*', re.UNICODE|re.IGNORECASE|re.DOTALL)
n = len(tables) -1
rep_tables = []
while n >= 0:
table = tables[n]
remove_invalid_tags(table)
table_text = unicodedata.normalize('NFKD', table.text).encode('ascii','ignore')
if re.search(identifier, table_text):
rep_tables += [table]
n -= 1
else:
n -= 1
return rep_tables
def remove_invalid_tags(soup, invalid_tags=['sup', 'br']): …Run Code Online (Sandbox Code Playgroud) 我正在尝试向以下页面发出POST请求:http://search.cpsa.ca/PhysicianSearch
为了模拟单击"搜索"按钮而不填写任何表单,这会向页面添加数据.在查看chrome开发人员工具中的网络选项卡时,通过单击按钮获取POST标头信息.我发布这个而不是仅仅从其他类似问题复制解决方案的原因是我相信我可能没有得到正确的标题信息.格式是否正确,我是否抓住了正确的信息?我之前从未发过过POST请求.
这就是我设法拼凑的东西:
import urllib.parse
import urllib.request
data = urllib.parse.urlencode({'Host': 'search.cpsa.ca', 'Connection': 'keep-alive', 'Content-Length': 23796,
'Origin': 'http://search.cpsa.ca', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Cahce-Control': 'no-cache', 'X-Requested-With': 'XMLHttpRequest',
'X-MicrosoftAjax': 'Delta=true', 'Accept': '*/*',
'Referer': 'http://search.cpsa.ca/PhysicianSearch',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-GB,en-US;q=0.8,en;q=0.6',
'Cookie': 'ASP.NET_SessionId=kcwsgio3dchqjmyjtwue402c; _ga=GA1.2.412607756.1459536682; _gat=1'})
url = "http://www.musi-cal.com/cgi-bin/query?%s"
data = data.encode('ascii')
with urllib.request.urlopen("http://search.cpsa.ca/PhysicianSearch", data) as f:
print(f.read().decode('utf-8'))
Run Code Online (Sandbox Code Playgroud)
此解决方案输出页面的HTML,但不包含我想要从POST请求中检索的任何数据.
我试图在一天之内使用Python和Scrapy从所有国家的所有机场取消所有出发和到达.
这个着名站点(飞行雷达)使用的JSON数据库需要在一个机场的出发或到达> 100时逐页查询.我还根据查询的实际UTC计算时间戳.
我尝试使用此层次结构创建数据库:
country 1
- airport 1
- departures
- page 1
- page ...
- arrivals
- page 1
- page ...
- airport 2
- departures
- page 1
- page ...
- arrivals
- page
- page ...
...
Run Code Online (Sandbox Code Playgroud)
我使用两种方法按页面计算时间戳和网址查询:
def compute_timestamp(self):
from datetime import datetime, date
import calendar
# +/- 24 heures
d = date(2017, 4, 27)
timestamp = calendar.timegm(d.timetuple())
return timestamp
def build_api_call(self,code,page,timestamp):
return 'https://api.flightradar24.com/common/v1/airport.json?code={code}&plugin\[\]=&plugin-setting\[schedule\]\[mode\]=&plugin-setting\[schedule\]\[timestamp\]={timestamp}&page={page}&limit=100&token='.format(
code=code, page=page, timestamp=timestamp)
Run Code Online (Sandbox Code Playgroud)
我将结果存储到CountryItem包含许多AirportItem机场的结果中.我 …
我正试图从网站上删除产品名称.奇怪的是,我似乎只抓了12件物品.我已经尝试了HtmlAgilityPack和HTTPClient,我得到了相同的随机结果.这是我的HtmlAgilityPack代码:
using HtmlAgilityPack;
using System.Net.Http;
var url = @"http://www.roots.com/ca/en/men/tops/shirts-and-polos/";
HtmlWeb web = new HtmlWeb();
var doc = web.Load(url, "GET", proxy, new NetworkCredential(PROXY_UID, PROXY_PWD, PROXY_DMN));
var nodes = doc.DocumentNode.Descendants("div")
.Where(div => div.GetAttributeValue("class", string.Empty) == "product-name")
.Select(div => div.InnerText.Trim())
;
Run Code Online (Sandbox Code Playgroud)
[更新1] @CodingKuma建议我试试Selenium Webdriver.这是我使用Selenium Webdriver的代码:
IWebDriver chromeDriver = new ChromeDriver(@"C:\TEMP\Projects\Chrome\chromedriver_win32");
chromeDriver.Url = "http://www.roots.com/ca/en/men/tops/shirts-and-polos/";
var items = chromeDriver.FindElements(By.ClassName("product-name"));
items.Count().Dump();
chromeDriver.Quit();
Run Code Online (Sandbox Code Playgroud)
我尝试了这段代码,但仍然没有运气.该页面上有20多个项目,但我似乎只是随机获得12.如何抓取该网站上的所有项目?
c# web-crawler web-scraping html-agility-pack selenium-webdriver
我在vba中结合IE编写了一个脚本,点击网页上地图上的一些点.单击一个点时,会弹出一个包含相关信息的小框.
我想解析每个盒子的内容.可以使用类名找到该框的内容contentPane.但是,这里主要关注的是通过单击这些点来生成每个框.当一个框出现时,它看起来如下图所示.
这是我到目前为止尝试过的脚本:
Sub HitDotOnAMap()
Const Url As String = "https://www.arcgis.com/apps/Embed/index.html?webmap=4712740e6d6747d18cffc6a5fa5988f8&extent=-141.1354,10.7295,-49.7292,57.6712&zoom=true&scale=true&search=true&searchextent=true&details=true&legend=true&active_panel=details&basemap_gallery=true&disable_scroll=true&theme=light"
Dim IE As New InternetExplorer, HTML As HTMLDocument
Dim post As Object, I&
With IE
.Visible = True
.navigate Url
While .Busy = True Or .readyState < 4: DoEvents: Wend
Set HTML = .document
End With
Application.Wait Now + TimeValue("00:0:07") ''the following line zooms in the slider
HTML.querySelector("#mapDiv_zoom_slider .esriSimpleSliderIncrementButton").Click
Application.Wait Now + TimeValue("00:0:04")
With HTML.querySelectorAll("[id^='NWQMC_VM_directory_'] circle")
For I = 0 To .Length - 1
.item(I).Focus
.item(I).Click …Run Code Online (Sandbox Code Playgroud) 我用Python编写了一个脚本,只在SO中显示我的个人资料中可见的名称.问题是我想使用请求模块登录该站点,一旦我登录,我希望使用Selenium获取配置文件名称.底线是 - 当我得到个人资料网址时,我希望Selenium重新使用该网址来获取个人资料名称.
此工作解决方案使用请求:
import requests
from bs4 import BeautifulSoup
url = "https://stackoverflow.com/users/login?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2f"
req = requests.get(url)
sauce = BeautifulSoup(req.text,"lxml")
fkey = sauce.select_one("[name='fkey']")['value']
payload = {
'fkey': fkey,
'ssrc': 'head',
'email': my_username,
'password': my_password,
'oauth_version':'',
'oauth_server':''
}
res = requests.post(url,data=payload)
soup = BeautifulSoup(res.text,"lxml")
item = soup.select_one("div[class^='gravatar-wrapper-']").get("title")
print(item)
Run Code Online (Sandbox Code Playgroud)
我现在想做的是:
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
url = "https://stackoverflow.com/users/login?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2f"
driver = webdriver.Chrome()
req = requests.get(url)
sauce = BeautifulSoup(req.text,"lxml")
fkey = sauce.select_one("[name='fkey']")['value']
payload = {
'fkey': fkey,
'ssrc': …Run Code Online (Sandbox Code Playgroud) web-scraping ×10
python ×5
curl ×2
php ×2
scrapy ×2
selenium ×2
asp.net ×1
c# ×1
edgar ×1
excel-vba ×1
http ×1
httprequest ×1
post ×1
powerbi ×1
python-3.x ×1
recursion ×1
vba ×1
web-crawler ×1
yield ×1